# 斐波那契数列
def fib(n):
    if n < 2:
        return n
    else:
        return fib(n - 2) + fib(n - 1)


print(fib(7))


# 快排
def quick(qlist):
    if len(qlist) == 0:
        return qlist
    else:
        qb = qlist[0]
        qa = quick([l for l in qlist[1:] if l <= qb])
        qc = quick([m for m in qlist[1:] if m > qb])
        return qa + [qb] + qc


print(quick([34, 2, 53, 1, 24, 63]))


# 随机插入排序
def insertQuick(qlist):
    for i in range(len(qlist)):
        key = qlist[i]
        j = i - 1
        while j >= 0 and key < qlist[j]:
            qlist[j + 1] = qlist[j]
            j -= 1
            qlist[j + 1] = key
    return qlist


print(insertQuick([34, 2, 53, 1, 24, 63]))


# 99乘法表
def n_n():
    for i in range(1, 10):
        for j in range(1, i + 1):
            print(f'{j}*{i}={j * i}  ', end=' ')
        print('\t')


print(n_n())


# 统计字符串中出现次数最多的字符和次数
def str1():
    str1 = 'ANSHJDJHsoijadOIJSDi'
    d1 = {}
    for i in str1:
        if i not in d1:
            d1[i] = 1
        else:
            d1[i] += 1

    for k, v in d1.items():
        if v == max(d1.values()):
            print(k, v)
    print(d1)


str1()


# Switch语句
def swch():
    sd1 = {
        "a": "a-1",
        "b": "b-2",
        "c": "c-3"
    }
    print(sd1["b"])


print("开关语句：", swch())


# filter()筛选功能
def name(name):
    if name.startswith('岳'):
        return True


print(list(filter(name, ["刘丽", "刘大能", "岳飞"])))


# map()映射方法
def abc(i):
    i = 15 + i
    return i


print(list(map(abc, [2, 354, 51, 2])))


# 获取list索引位置
def lSonr(l1):
    list1 = [2, 34, 2, 35, 25]
    if l1 in list1:
        print(list1.index(l1))
    else:
        print("您输入的数字不在列表中！")


lSonr(35)


# 判断字符串中大写的几个，小写的几个
def bs():
    str1 = "iwjeiAJOWIJEijWE"
    b = 0
    s = 0
    for i in str1:
        if i.islower():
            s += 1
        else:
            b += 1
    print(b, s)


bs()


# 修改元组内部元素不可修改的元素
def tp():
    t1 = (1, 2, 3, [4, 34, 234, 24312], "外地", "123")
    t1[3].extend([3434, 34342])
    t1[3].append(12123)
    t1[3].insert(2, (34, 5))
    print(t1)
    return t1


tp()
# 列表推导式
list1 = [l for l in range(10)]
print(list1)
# 集合推导式
set1 = {s for s in range(10)}
print(set1)

# 字典推导式
list2 = [1, 2, 3, 4, 5, 6]
d1 = {i: list2[i] for i in range(len(list2))}
print(d1)


# 函数嵌套
def wapper(name):
    i = 1

    def inner(*args, **kwargs):
        nonlocal i
        i = 34567
        name1 = name(*args, **kwargs)
        return name1

    return inner


# 迭代器
list3 = [3, 342, 542, 51, 36, 53]
l3 = list3.__iter__()
print(l3.__next__())
print(l3.__next__())
print(l3.__next__())
print(l3.__next__())
print(l3.__next__())
print(l3.__next__())


# 生成器
def shengchengqi():
    i = 23
    c = "第一个返回"
    yield i, c
    scc = 1
    yield scc


cc = shengchengqi()

print(cc.__next__())

print(cc.__next__())


# 装饰器
def wrapper(name):
    i = 123

    def inner(*args, **kwargs):
        nonlocal i
        i = 456
        print(i)
        returnName = name(*args, **kwargs)
        print(args, kwargs)
        return returnName
    return inner


@wapper  # game = wrapper(game)
def game(username, password):
    print(f'game内执行的用户名密码是：{username, password}')
    return "游戏开始"


print(game(username="岳小亭", password="周抗抗"))
